<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.DataInputStream"%>
<%@page import="java.io.File"%>
<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<jsp:useBean id="user" class="serverDB_classes.UserData" scope="session"/> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255">
<title>Insert title here</title>
</head>
<body><%
File file=new File((String)session.getAttribute("fileName"));
	response.setContentType("application/octet-stream");
	response.setContentLength((int) file.length());
	response.setHeader(
	        "Content-Disposition","attachment; filename="+file.getName() );
	 response.setContentLength( (int) file.length( ) );
	 int length = 0;
		DataInputStream inFile = null;
		ServletOutputStream outFile = null;
		
		try {
			inFile = new DataInputStream(new FileInputStream(file));
			outFile = response.getOutputStream();

			byte[] buffer = new byte[4096];

			while ((inFile != null) && ((length = inFile.read(buffer)) != -1)) {
				outFile.write(buffer, 0, length);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (inFile != null) {
					inFile.close();
				}
				if (out != null) {
					outFile.flush();
					//out.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	
%>
</body>
</html>